<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class AutoReply extends Model
{
    protected $fillable = ['work_id','content','type'];
    protected $table = "c_auto_replies";

    /**
     * @param $filter
     * @return mixed
     * 添加/编辑
     */
    public function add($filter)
    {
        if (isset($filter['id'])) {
            unset($filter['api_token']);
            return $this::where([['id','=',$filter['id']]])->update($filter);
        } else {
            return $this->create($filter);
        }
    }

    /**
     * @param $filter
     * @return mixed
     * 删除
     */
    public function del($filter)
    {
        return $this::destroy($filter['id']);
    }
    
    
    /**
     * 列表
     */
    public function getList($filter)
    {
        $res = $this->where([['work_id','=',$filter['work_id']]])->orderBy("type","asc")->orderBy("id","desc")->get();
        if(!empty($res)){
            return $res->toArray();
        }
        return [];
    }

}
